/*! \file programme.test.cpp
    \brief Un programme c++ pour tester l'instrumentation
*/

#include <cstdlib>


void randomAlloc(int n)
{
  char* mem = (char*)malloc(n);
  mem = (char*)realloc(mem,10);		
	
  free(mem);
};

float sinus(float x){
  
  void *c=malloc(22);
  free(c);
  return 0;
};



class MyAllocator{
  private:
	void *ptr;
  public:
        void* allocate(size_t n){
           ptr = malloc(n);
           return ptr;
        }
        void restore(void* ptr){
           free(ptr);
           float x=sinus((float)(long int) ptr);
	}
};
int steps=100;

#include <stdio.h>
#include <string.h>

int main(int argc,char* argv[]){
   if(argc ==2){
	steps=atoi(argv[1]);
   }
   randomAlloc(100);
   MyAllocator a;
   for(int i=1;i<=steps;i++){
     void * x=a.allocate(100);
     a.restore(x);
     for(int j=0;j<4000;j++){};
   }
   printf("@ : %p\n",sinus);
   return 0;
}
